from appium import webdriver
import time
from selenium.webdriver.common.by import By
from appium.webdriver.extensions.android.nativekey import AndroidKey


# def case():
desired_caps={
    'platformName': 'Android', # 被测手机是安卓
    'platformVersion': '5.1.1', # 手机安卓版本
    'deviceName': 'ye_shen', # 设备名，安卓手机可以随意填写
    'appPackage': 'com.ss.android.ugc.aweme', # 启动APP Package名称
    'appActivity': 'com.ss.android.ugc.aweme.splash.SplashActivity', # 启动Activity名称
    'unicodeKeyboard': True, # 使用自带输入法，输入中文时填True
    'resetKeyboard': True, # 执行完程序恢复原来输入法
    'noReset': True,       # 不要重置App
    'newCommandTimeout': 6000,
     'automationName' : 'UiAutomator2'
}

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)
time.sleep(10)
#翻页
size = driver .get_window_size()
start_x = size['width']*0.5
start_y = size['height']*0.8
end_y = size['height']*0.2
for i in range(3):
    driver.swipe(start_x,start_y,start_x,end_y,300)
    time.sleep(8)
#diansou
driver.find_element(by=By.ID,value='com.ss.android.ugc.aweme:id/h4o').click()
time.sleep(10)
driver.find_element(by=By.CLASS_NAME,value='com.smile.gifmaker:id/editor').clear()
time.sleep(10)
driver.find_element(by=By.CLASS_NAME,value='com.smile.gifmaker:id/editor').send_keys('小王子')
time.sleep(10)
driver.find_element(by=By.ID,value='com.smile.gifmaker:id/right_tv').click()
time.sleep(10)
#shi
driver.find_element(By.XPATH,value='//*[@text="视频"]').click()
time.sleep(10)
#yong
driver.find_element(By.XPATH,value='//*[@text="用户"]').click()
time.sleep(10)
#zhi
driver.find_element(By.XPATH,value='//*[@text="直播"]').click()
time.sleep(10)
#fan
driver.find_element(By.ID,value='com.smile.gifmaker:id/left_image').click()
time.sleep(10)
#fan2
driver.find_element(By.ID,value='com.smile.gifmaker:id/left_btn').click()
time.sleep(10)
#shang
driver.find_element(By.XPATH,value='//*[@text="商城"]').click()
time.sleep(10)
#点击关注
driver.find_element(By.ID,value='com.smile.gifmaker:id/slide_play_right_follow_button').click()
time.sleep(8)
#点赞
driver.find_element(By.ID,value='com.smile.gifmaker:id/like_button').click()
time.sleep(8)
#评论
driver.find_element(By.ID,value='com.smile.gifmaker:id/comment_button').click()
time.sleep(8)